﻿
function setDomain(value){
	$("#domain").attr("value",$.trim(value));
}

function setUsername(value){
	$("#username").attr("value",$.trim(value));
}

/**
 * 检查用户名
 * @return
 */
function chkUsername() {
	var username = $.trim($("#inp_uname").val());
	if(username=="") {
		return 0;
	}
	else if( /^\d.*$/.test( username ) ){
		//用户名不能以数字开头
		return -1;
	}
	else if(fLen( username )<6 || fLen( username )>18 ){
		//合法长度为6-18个字符
		return -2;
	}
	else if(! /^\w+$/.test( username ) ){
		//用户名只能包含_,英文字母，数字
		return -3;
	}
	else if(! /^([a-z]|[A-Z])[0-9a-zA-Z_]+$/.test( username ) ){
		//用户名只能英文字母开头
		return -4;
	}
	else if(!(/[0-9a-zA-Z]+$/.test( username ))){
		//用户名只能英文字母或数字结尾
		return -5;
	}
	return 1;
}

$(document).ready(function(){
	/** ----------- 用户名输入框事件 ----------- */
	$("#inp_uname").bind("focus", function(){
		var ret=chkUsername();
		$("#inp_uname").attr("class","inp ipt-focus");
		if(ret==0){
			//用户名输入框为空,显示规则
			$("#inp_uname").attr("class","inp ipt-normal");
			$("#div_uname_rule").show();
			if($("#password_ico_err").is(":visible")){
				$("#div_password_err").hide();
			}
		}
		return false;
	});
	
	
	$("#inp_uname").bind("blur", function(){
		
		var ret=chkUsername();
		if(ret>0) {
			if($("#inp_uname").val()==$("#tmp").val()) return false;
			$("#inp_uname").attr("class","inp ipt-normal");
			$("#div_uname_rule").hide();
			$("#uname_ico_err").hide();
			//$("#uname_ico_ok").hide();
			$("#div_uname_err").hide();
			//setUsername($("#inp_uname").val());
			//doParameterRequest('chkUname.jsp','inp_uname','domain');
			url="chkUname.jsp?username="+$.trim($("#inp_uname").val())+"&domain="+$.trim($("#domain").val());
			doRequest(url);
		}
		else if(ret==0){
			//用户名输入框为空,显示规则
			$("#tmp").attr("value","");
			$("#inp_uname").attr("class","inp ipt-normal");
			$("#div_uname_rule").hide();
			$("#div_uname_err").hide();
			$("#uname_ico_err").hide();
			//$("#uname_ico_ok").hide();
			$("#tr_chk_username_result").hide();
			//$("#div_uname_err_info").html("");
		}
		else {
			$("#tmp").attr("value","");
			$("#tr_chk_username_result").hide();
			//更改用户名标签样式
			$("#inp_uname").attr("class","inp ipt-error");
			//显示错误提示图标
			$("#uname_ico_err").show();
			//隐藏正常提示内容div
			$("#div_uname_rule").hide();
			//打开用户名检查错误div
			$("#div_uname_err").show();
			if(ret == -1){
			//显示具体的错误内容
			$("#div_uname_err_info").html("用户名不能以数字开头");
		}
		else if(ret == -2){
			$("#div_uname_err_info").html("合法长度为6-18个字符");
		}
		else if(ret == -3){
			$("#div_uname_err_info").html("用户名只能包含_,英文字母,数字 ");
		}
		else if(ret == -4){
			$("#div_uname_err_info").html("用户名只能英文字母开头");
		}
		else if(ret == -5){
			$("#div_uname_err_info").html("用户名只能英文字母或数字结尾");
		}
		}
		
		if($("#password_ico_err").is(":visible")){
			$("#div_password_err").show();
		}
		return false;
	});
	
	$("#inp_uname").bind("keydown", function(event){
		//event = fGetEvent();
		if (event.keyCode == 13) { 
			if(event.preventDefault) {    
		        // Firefox    
				event.preventDefault();    
				event.stopPropagation();    
		     } else {    
		        // IE    
		    	 event.cancelBubble=true;    
		    	 event.returnValue = false;    
		     }  
			$("#inp_uname").blur();
		}
		return true;
	});
	/** --------- end ------------ */
	
	/** ----------- 密码输入框事件 ----------- */
	$("#password").bind("focus", function(){
		//check account radio
		if($("input[name='rdAccount'][checked]").val()==undefined){
			$("#div_chose_uname").attr("class","chose-list notice");
		}
		
		ret = chkPassword();
		$("#password").attr("class","inp ipt-focus");
		if(ret==0){
			if($("#password_ico_err").is(":visible")){
				$("#div_password_err").hide();
				$("#password_ico_err").hide();
			}
			$("#div_password_rule").show();
			//恢复重复输入密码状态
			$("#div_passwordconfirm_err").hide();
			$("#passwordconfirm").attr("class","inp ipt-normal");
			$("#passwordconfirm").attr("value","");
			$("#passwordconfirm_ico_ok").hide();
			$("#passwordconfirm_ico_err").hide();
		}
		else if(ret>0) {
			chkPasswordStrong($("#password").val());
		}
		return false;
	});
	$("#password").bind("blur", function(){
		ret = chkPassword();
		if(ret>0){
			$("#password").attr("class","inp ipt-normal");
			$("#password_ico_ok").show();
			$("#password_ico_err").hide();
			$("#div_password_rule").hide();
			$("#div_password_err").hide();
			$("#div_password_err_info").html("");
		}
		else {
			if(ret==0){
			$("#password").attr("class","inp ipt-normal");
			$("#password_ico_ok").hide();
			$("#password_ico_err").hide();
			$("#div_password_rule").hide();
			$("#div_password_err").hide();
			$("#div_password_err_info").html("");
		}
		else if(ret==-1){
			$("#password").attr("class","inp ipt-error");
			$("#password_ico_ok").hide();
			$("#password_ico_err").show();
			$("#div_password_rule").hide();
			$("#div_password_err").show();
			$("#div_password_err_info").html("请输入6～16位字符的密码");
			
		}
		}
		return false;
	});
	$("#password").bind("keyup", function(){
		$("#passwordconfirm").attr("value","");
		//检查密码强度
		chkPasswordStrong($("#password").val());
		return false;
	});
	
	$("#passwordconfirm").bind("blur",function(){
		$("#passwordconfirm").attr("class","inp ipt-normal");
		return chkPasswordconfirm();
	}
	);
	/** --------- end ------------ */
	
	/** ----------- 保护问题和答案事件 ----------- */
	$("#cusproblem").bind("focus",function(){
		$("#cusproblem").addClass("inp ipt-normal");
		$("#cusproblem_ico_err").hide();
		$("#cusproblem_ico_ok").hide();
		$("#div_cusproblem_err").hide();
		$("#div_cusproblem_rule").show();
		return false;
	});
	$("#cusproblem").bind("keydown",function(event){
		event = event ? event : (window.event ? window.event : null);
		var k = event.keyCode;
		if (8 != k && !(event.ctrlKey && (k == 65 || k == 67 || k == 88)) && 46 != k && 37 != k && 39 != k && 35 != k && 36 != k && !(event.shiftKey && (k == 35 || k == 36))) {
			var val = $.trim($("#cusproblem").val());
			if(fLen(val) >= 36) {
				if(event.preventDefault) {    
			        // Firefox    
					event.preventDefault();    
					event.stopPropagation();    
			    } else {    
			        // IE    
			    	event.cancelBubble=true;    
			    	event.returnValue = false;    
			    }
				return false;
			}
		}
		return true;
	});
	$("#cusproblem").bind("blur",function(){
		$("#cusproblem").attr("class","inp ipt-normal");
		ret=chkCustomProblem();
		if(ret==0){
			$("#cusproblem").attr("class","inp ipt-normal");
			$("#cusproblem_ico_err").hide();
			$("#cusproblem_ico_ok").hide();
			$("#div_cusproblem_err").hide();
			$("#div_cusproblem_rule").hide();
		}
		else if(ret<0){
			$("#cusproblem").attr("class","inp ipt-error");
			$("#cusproblem_ico_err").show();
			$("#cusproblem_ico_ok").hide();
			$("#div_cusproblem_err").show();
			if (-1 == ret) {
				$("#div_cusproblem_err_info").html("长度太短:6～36个字符,一个汉字占两个字符");
			} else {
				$("#div_cusproblem_err_info").html("长度太长:6～36个字符,一个汉字占两个字符");
			}
			$("#div_cusproblem_rule").hide();
		}
		else {
			$("#cusproblem").attr("class","inp ipt-normal");
			$("#cusproblem_ico_err").hide();
			$("#cusproblem_ico_ok").show();
			$("#div_cusproblem_err").hide();
			$("#div_cusproblem_rule").hide();
			$("#div_cusproblem_err_info").html("");
		}
	}	
	);
	
	$("#secanswer").bind("focus",function(){
		$("#secanswer").addClass("inp ipt-normal");
		$("#secanswer_ico_err").hide();
		$("#secanswer_ico_ok").hide();
		$("#div_secanswer_err").hide();
		$("#div_secanswer_rule").show();
		return false;
	});
	$("#secanswer").bind("blur",function(){
		$("#secanswer").attr("class","inp ipt-normal");
		ret=chkSecAnswer();
		if(ret==0){
			$("#secanswer").addClass("inp ipt-normal");
			$("#secanswer_ico_err").hide();
			$("#secanswer_ico_ok").hide();
			$("#div_secanswer_err").hide();
			$("#div_secanswer_rule").hide();
		}
		else if(ret<0){
			$("#secanswer").addClass("inp ipt-error");
			$("#div_secanswer_rule").hide();
			$("#secanswer_ico_err").show();
			$("#secanswer_ico_ok").hide();
			$("#div_secanswer_err").show();
			$("#div_secanswer_err_info").html("问题答案是:4～30个字符,一个汉字占两个字符");
		}
		else {
			$("#secanswer").addClass("inp ipt-normal");
			$("#secanswer_ico_err").hide();
			$("#secanswer_ico_ok").show();
			$("#div_secanswer_err").hide();
			$("#div_secanswer_rule").hide();
		}
		return false;
	}	
	);
	/** --------- end ------------ */
	
	/** ----------- 真实姓名事件 ----------- */
	$("#realname").bind("focus",function(){		
		$("#realname").attr("class","inp ipt-normal");
		$("#realname_ico_err").hide();
		$("#realname_ico_ok").hide();
		//$("#div_realname_err").hide();
		$("#div_realname_err").show();
		$("#div_realname_err").attr("class","info-pop");
		$("#div_realname_err_info").html("请输入您的真实姓名,长度2-10个中文字符.(如:张三,李四)");
		return false;
	});
	
	$("#realname").bind("blur",function(){
		ret=chkrealname();
		if(ret==0){
			//用户名输入框为空,显示规则
			$("#realname").attr("class","inp ipt-normal");
			$("#realname_ico_err").hide();
			$("#realname_ico_ok").hide();
			$("#div_realname_err").hide();
		}
		else if(ret>0){			
			$("#realname").attr("class","inp ipt-normal");
			$("#realname_ico_err").hide();
			$("#realname_ico_ok").show();
			$("#div_realname_err").hide();
			$("#div_realname_err_info").html("");
		}
		
		else{
			
			$("#realname").attr("class","inp ipt-error");
			$("#realname_ico_ok").hide();
			$("#realname_ico_err").show();
			$("#div_realname_err").show();
			$("#div_realname_err").attr("class","info-pop I-error");
            if(ret == -1){
			$("#div_realname_err_info").html("请输入中文姓名!");
		}
		
		else if(ret == -2){
			$("#div_realname_err_info").html("输入的姓名长度不合法!");
		}
		}
			
		return false;
	}
	);
	/** --------- end ------------ */
	
	
	
	/** ----------- 出生日期事件 ----------- */
	$("#year").bind("focus", function(){
		if(chkYear()==0&&chkMonth()==0&&chkDay()==0){
			$("#div_birthday_err").attr("class","info-pop");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").show();
			$("#div_birthday_err_info").text("用来取回密码，请正确填写");
		}
	});
	$("#year").bind("blur",function(){
		$("#year").attr("class","inp ipt-normal");
		ret=chkYear();
		if(ret==0){
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
		}
		else if(ret<0){
			$("#year").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err_info").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").html("输入的年份有错误");
			//$("#month").focus();
			//document.getElementById('inp_uname').focus();
		}
		else {
			$("#year").attr("class","inp ipt-normal");
			//$("#birthday_ico_ok").show();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
			
			var i = chkMonth();
			var j = chkDay();
			if(i>0&&j>0) {
				$("#birthday_ico_ok").show();
				$("#day").attr("class","inp ipt-normal");
				$("#month").attr("class","inp ipt-normal");
			}
			else if(i==0&&j==0){
			}
			else {
				$("#birthday_ico_ok").hide();
				$("#birthday_ico_err").show();
				$("#div_birthday_err").show();
				$("#div_birthday_err").attr("class","info-pop I-error");
				$("#div_birthday_err_info").show();
				$("#div_birthday_err_info").html("输入的日期有错误");
				if(i<=0){
					$("#month").attr("class","inp ipt-error");
				}
				if(j<=0){
					$("#day").attr("class","inp ipt-error");
				}
			
			}
		}
		return false;
	}	
	);
	$("#year").bind("keyup",function(){
		$("#year").attr("class","inp ipt-normal");
		year = $.trim($("#year").val());
		if(year>999){
			ret=chkYear();
			if(ret<0){
				$("#year").attr("class","inp ipt-error");
				$("#birthday_ico_ok").hide();
				$("#birthday_ico_err").show();
				$("#div_birthday_err").show();
				$("#div_birthday_err").attr("class","info-pop I-error");
				$("#div_birthday_err_info").show();
				$("#div_birthday_err_info").html("输入的年份有错误");
			}
			else {
				$("#year").attr("class","inp ipt-normal");
				$("#birthday_ico_err").hide();
				$("#div_birthday_err").hide();
				$("#div_birthday_info").hide();
				$("#month").focus();
			}
		}
		return false;
	}
	);
	
	$("#month").bind("blur",function(){
		$("#month").attr("class","inp ipt-normal");
		ret=chkMonth();
		if(ret==0){
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
		}
		else if(ret<0){
			$("#month").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").show();
			$("#div_birthday_err_info").html("输入的月份有错误");
			//$("#day").focus();
		}
		else {
			$("#month").attr("class","inp ipt-normal");
			//$("#birthday_ico_ok").show();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
			$("#div_birthday_info").hide();
			//$("#day").focus();
			var i = chkYear();
			var j = chkDay();
			if(i>0&&j>0) {
				$("#birthday_ico_ok").show();
				$("#day").attr("class","inp ipt-normal");
				$("#year").attr("class","inp ipt-normal");
			}
			else if(i==0&&j==0){
			}
			else {
				$("#birthday_ico_ok").hide();
				$("#birthday_ico_err").show();
				$("#div_birthday_err").show();
				$("#div_birthday_err").attr("class","info-pop I-error");
				$("#div_birthday_err_info").show();
				$("#div_birthday_err_info").html("输入的日期有错误");
				if(i<=0){
					$("#year").attr("class","inp ipt-error");
				}
				if(j<=0){
					$("#day").attr("class","inp ipt-error");
				}
			}
		}
		return false;
	}	
	);
	$("#month").bind("keyup",function(){
		$("#month").attr("class","inp ipt-normal");
		month = $.trim($("#month").val());
		if(month>9){
		ret=chkMonth();
		if(ret<0){
			$("#month").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").show();
			$("#div_birthday_err_info").html("输入的月份有错误");
		}
		else {
			$("#month").attr("class","inp ipt-normal");
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
			$("#div_birthday_info").hide();
			$("#day").focus();
		}
		}
		return false;
	}	
	);
	
	$("#day").bind("blur",function(){
		$("#day").attr("class","inp ipt-normal");
		ret=chkDay();
		if(ret==0){
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
		}
		else if(ret<0 || chkYear()<1 || chkMonth()<1){
			$("#day").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").show();
			if(ret>0) $("#day").attr("class","inp ipt-normal");
			$("#div_birthday_err_info").html("输入的出生日期有错误");
		}
		else if(chkYear()>0&&chkMonth()>0){
			var startDate=new Date();
			startDate.setFullYear(1901,0,2);
			var myDate=new Date();
			myDate.setFullYear($.trim($("#year").val()),parseInt($.trim($("#month").val())-1),$.trim($("#day").val()));
			var today=new Date();
			if(ret<1 || myDate>today || myDate<startDate){
				$("#year").attr("class","inp ipt-error");
				$("#month").attr("class","inp ipt-error");
				$("#day").attr("class","inp ipt-error");
				$("#birthday_ico_ok").hide();
				$("#birthday_ico_err").show();
				$("#div_birthday_err").show();
				$("#div_birthday_err").attr("class","info-pop I-error");
				$("#div_birthday_err_info").show();
				$("#div_birthday_err_info").html("输入的日期在无效范围内,请重新输入!");
			}
			else {
			$("#day").attr("class","inp ipt-normal");
			$("#year").attr("class","inp ipt-normal");
			$("#month").attr("class","inp ipt-normal");
			$("#birthday_ico_ok").show();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
			}
		}
		return false;
	}	
	);
	
	$("#day").bind("keyup",function(){
		$("#day").attr("class","inp ipt-normal");
		ret=chkDay();
		
		if(ret<0 || chkYear()<1 || chkMonth()<1){
			$("#day").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").show();
			if(ret>0) $("#day").attr("class","inp ipt-normal");
			$("#div_birthday_err_info").html("输入的出生日期有错误");
		}
		else if(chkYear()>0&&chkMonth()>0){
			var startDate=new Date();
			startDate.setFullYear(1901,0,2);
			var myDate=new Date();
			myDate.setFullYear($.trim($("#year").val()),parseInt($.trim($("#month").val())-1),$.trim($("#day").val()));
			var today=new Date();
			if(ret<1 || myDate>today || myDate<startDate){
				$("#year").attr("class","inp ipt-error");
				$("#month").attr("class","inp ipt-error");
				$("#day").attr("class","inp ipt-error");
				$("#birthday_ico_ok").hide();
				$("#birthday_ico_err").show();
				$("#div_birthday_err").show();
				$("#div_birthday_err").attr("class","info-pop I-error");
				$("#div_birthday_err_info").show();
				$("#div_birthday_err_info").html("输入的日期在无效范围内,请重新输入!");
			}
			else {
			$("#day").attr("class","inp ipt-normal");
			$("#year").attr("class","inp ipt-normal");
			$("#month").attr("class","inp ipt-normal");
			$("#birthday_ico_ok").show();
			$("#birthday_ico_err").hide();
			$("#div_birthday_err").hide();
			}
		}
	}	
	);
	/** --------- end ------------ */
	
	/** ----------- 电子邮箱事件 ----------- */
	$("#email").bind("focus",function(){
		$("#email").attr("class","inp ipt-normal");
		$("#email_ico_err").hide();
		$("#email_ico_ok").hide();
		//$("#div_email_err").hide();
		$("#div_email_err").show();
		$("#div_email_err").attr("class","info-pop");
		$("#div_email_err_info").html("电子邮箱6～30个字符,为方便与您联系,请输入正确的邮箱格式(如:seaview@163.com)");
		return false;
	});
	$("#email").bind("blur",function(){
		ret=chkemail();
		if(ret==0){
			$("#email").attr("class","inp ipt-normal");
			$("#email_ico_err").hide();
			$("#email_ico_ok").hide();
			$("#div_email_err").hide();
		}
		else if(ret<0){
			$("#email").attr("class","inp ipt-error");
			$("#email_ico_ok").hide();
			$("#email_ico_err").show();
			$("#div_email_err").show();
			$("#div_email_err").attr("class","info-pop I-error");
			$("#div_email_err_info").html("输入的电子邮箱格式有错误！");
		}
		else {
			$("#email").attr("class","inp ipt-normal");
			$("#email_ico_err").hide();
			$("#email_ico_ok").show();
			$("#div_email_err").hide();
		}
		return false;
	}
	);
	/** --------- end ------------ */
	
	/** --------- 验证码 ------------ */
	$("#authcode").bind("blur",function(){
		ret=chkAuthcode();
		if(ret==0){
			//$("#authcode_ico_ok").hide();
			$("#authcode_ico_err").show();
			$("#div_authcode_err").show();
			$("#div_authcode_err_info").html("验证码不能为空");
		}
		else {
			//$("#authcode_ico_ok").show();
			$("#authcode_ico_err").hide();
			$("#div_authcode_err").hide();
		}
	});
	
	/** --------- end ------------ */
	
	/** --------- 绑定radio事件 ------------ */
	$("input[name='rdAccount']").bind("click", function(){
		if($(this).attr("disable")=='true'){
			return true;
		}
		var val=$.trim($(this).val());
		if(val=='') return true;

		array_tmp=val.split("@");
		setUsername(array_tmp[0]);
		setDomain("@"+array_tmp[1]);
		$('#st_domain').html("@"+array_tmp[1]);
		$('#st_userAtDomain').html(array_tmp[0]+"<span class='Cblue'>@"+array_tmp[1]+"</span>");
		$('#tr_chk_username_result').hide();
		$('#tr_input_username').hide();
		$('#tr_show_username').show();
		$('#div_chose_uname').attr('class','chose-list');
		//$('#uname_ico_ok').hide();
		return true;
		}); 
	/** --------- end ------------ */
	}); 

$(window).load(function(){bodyOnLoad();return false; });

function chkPassword(){
	password= $("#password").val();
	if(password == "") return 0;
	var len;
	var i;
	var isPassword = true;
	len = 0;
	for (i=0;i<password.length;i++){
		if (password.charCodeAt(i)>255) isPassword = false;
	}
	if(!isPassword || password.length > 16 || password.length < 6)
		return -1;
	
	return 1;
}

/**
 * 显示密码强弱
 * @return
 */
function chkPasswordStrong(me) {
	//恢复重复输入密码状态
	$("#div_passwordconfirm_err").hide();
	$("#passwordconfirm").attr("class","inp ipt-normal");
	$("#passwordconfirm_ico_ok").hide();
	$("#passwordconfirm_ico_err").hide();
	//-----
	$("#password_ico_ok").hide();
	$("#password_ico_err").hide();
	
	$("#div_password_err").hide();
	$("#div_password_err_info").html("");
	
	$("#password").attr("class","inp ipt-normal");
	//打开密码提示内容div
	$("#div_password_rule").show();
	var csint = checkStrong(me);
	$("#div_passowrd_Strong").attr("class","bar state"+csint);
}


function CharMode(iN){ 
	if (iN>=48 && iN <=57) //数字 
	return 1; 
	if (iN>=65 && iN <=90) //大写字母 
	return 2; 
	if (iN>=97 && iN <=122) //小写 
	return 4; 
	else 
	return 8; //特殊字符 
} 

function chkPasswordconfirm(){
	var password= $("#password").val();
	var passwordconfirm = $("#passwordconfirm").val();
	
	if(password != passwordconfirm){
		$("#div_passwordconfirm_err").show();
		$("#passwordconfirm").attr("class","inp ipt-error");
		$("#passwordconfirm_ico_ok").hide();
		$("#passwordconfirm_ico_err").show();
		return false;
	}
	else if(passwordconfirm==''){
		$("#div_passwordconfirm_err").hide();
		$("#passwordconfirm").attr("class","inp ipt-normal");
		$("#passwordconfirm_ico_ok").hide();
		$("#passwordconfirm_ico_err").hide();
	}
	else {
		$("#div_passwordconfirm_err").hide();
		$("#passwordconfirm").attr("class","inp ipt-normal");
		
		$("#passwordconfirm_ico_err").hide();
		if($("#password_ico_err").is(":visible")){
			$("#passwordconfirm_ico_ok").hide();
		}
		else $("#passwordconfirm_ico_ok").show();
	}
	return true;
}

//bitTotal函数 
//计算出当前密码当中一共有多少种模式 
function bitTotal(num){
	modes=0; 
	for (i=0;i<4;i++){ 
		if (num & 1) modes++; 
		num>>>=1; 
	} 
	return modes; 
} 

//checkStrong函数 
//返回密码的强度级别 
function checkStrong(sPW){
	Modes=0; 
	for (i=0;i<sPW.length;i++){ 
		//测试每一个字符的类别并统计一共有多少种模式. 
		Modes|=CharMode(sPW.charCodeAt(i)); 
	} 
	return bitTotal(Modes);
}
/**
 * 获取事件
 * @param e
 * @return
 */
function fGetEvent (e) {
	var ev = e || window.event;
	
	if (!ev) {
		var aCaller = [];
		var c = fGetEvent.caller;
		while (c) {
			ev = c.arguments[0];
			if (ev && Event == ev.constructor) {
				break;
			}
			
			var b = false;
			for(var i=0;i<aCaller.length;i++){
				if(c == aCaller[i]){
					b = true;
					break;
				}
			}
			if(b){
				break;
			}else{
				aCaller.push(c);
			}
			c = c.caller;
		}
	}

	return ev;
}

function changeQuestion(me)
{
    if ( me.value == "cusproblem" )
    {
    	$("#tr_cusproblem").show();
    }
    else{
    	$("#tr_cusproblem").hide();
    	if(me.value!=0) $("#div_secproblem_err").hide();
    }
}

//检查自定义问题
function chkCustomProblem(){
	var val = $.trim($("#cusproblem").val());
	if(fLen(val)==0){
		return 0;
	} 
	else if(fLen(val)<6) {
		return -1;
	}
	else if(fLen(val)>36){
		return -2;
	}
	else return 1;
}

//检查密码保护问题答案
function chkSecAnswer(){
	var val = $.trim($("#secanswer").val());
	if(fLen(val)==0){
		return 0;
	}
	else if(fLen(val)<4 || fLen(val)>30){
		return -1;
	}
	else return 1;
}


//检查真实姓名输入的中文字符
function chkrealname(){
	realname=$.trim($("#realname").val());
	if(realname=="") return 0;
	
	else if(/^[u4E00-u9FA5]+$/.test( realname )){		
	    //真实姓名只允许中文字符
	    return -1;
	}
	
	else if(fLen( realname )<4 || fLen( realname )>24 ){
		//合法长度为2-12个中文字符
		return -2;
	}
	else return 1
}


//计算字符数，一个中文2个字符
function fLen(Obj){
  var nCNLenth = 0;
  var nLenth = Obj.length;
  for (var i=0; i<nLenth; i++){
    if(Obj.charCodeAt(i)>255){
      nCNLenth += 2; 
    }else{
      nCNLenth++;
    }
  }
  return nCNLenth;
}

function checkNumber( num ,max){
    if( /^[0-9]+$/.test( num ) && num <=max && num > 0)
		return true;
	else return false;
}
function chkYear(){
	year = $.trim($("#year").val());
	if (year=="") return 0;
	if (!checkNumber(year,new Date().getFullYear()) || parseInt(year) < 1901) return -1;
	return 1;
}
function chkMonth(){
	month = $.trim($("#month").val());
	if(month=="") return 0;
	if (!checkNumber(month,12)) return -1;
	return 1;
}
function chkDay(){
	day = $.trim($("#day").val());
	if (day=="") return 0;
	m = $.trim($("#month").val());
	maxday=31;
	if(m!=null || m!=""){
		switch(parseInt(m)){
		case 1:
			maxday=31
			break
		case 2:
			if(isLeapYear($.trim($("#year").val())))
			maxday=29
			else maxday=28
			break
		case 3:
			maxday=31
			break
		case 4:
			maxday=30
			break
		case 5:
			maxday=31
			break
		case 6:
			maxday=30
			break
		case 7:
			maxday=31
			break
		case 8:
			maxday=31
			break
		case 9:
			maxday=30
			break
		case 10:
			maxday=31
			break
		case 11:
			maxday=30
			break
		case 12:
			maxday=31
			break
		default:
			maxday=31;
		}
	}
	if (!checkNumber(day,maxday)) return -1;
	return 1;
}

//检查电子邮箱输入的格式
function chkemail(){
	email=$.trim($("#email").val());
	if(email=="") return 0;
	if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test( email ) )
	
		return 1;
	return -1;
}

function chkAuthcode(){
	authcode=$.trim($("#authcode").val());
	if(authcode=="") return 0;
	return 1;
}

function doRegFormSubmit(){
	if(a==0){
		alert("请选择用户名!");
		return false;
	}
	
	ret = chkUsername();
	if(ret<1) {
		ok = false;
		$("#tr_chk_username_result").hide();
		//更改用户名标签样式
		$("#inp_uname").attr("class","inp ipt-error");
		//显示错误提示图标
		$("#uname_ico_err").show();
		//隐藏正常提示内容div
		$("#div_uname_rule").hide();
		//打开用户名检查错误div
		$("#div_uname_err").show();
		if(ret == 0){
			$("#div_uname_err_info").html("用户名不能为空");
		}
		else if(ret == -1){
			//显示具体的错误内容
			$("#div_uname_err_info").html("用户名不能以数字开头");
		}
		else if(ret == -2){
			$("#div_uname_err_info").html("合法长度为6-18个字符");
		}
		else if(ret == -3){
			$("#div_uname_err_info").html("由数字、26个英文字母或者下划线组成的字符串 ");
		}
		else if(ret == -4){
			$("#div_uname_err_info").html("用户名只能包含_,英文字母,数字");
		}
	}

	ret = chkPassword();
	if(ret<1){
		ok=false;
		$("#password").attr("class","inp ipt-error");
		$("#password_ico_ok").hide();
		$("#password_ico_err").show();
		$("#div_password_rule").hide();
		$("#div_password_err").show();
		$("#div_password_err_info").html("请输入6～16位字符的密码");
	}
	else {
		if(!chkPasswordconfirm()){
			ok=false;
			$("#div_passwordconfirm_err").show();
			$("#passwordconfirm").attr("class","inp ipt-error");
			$("#passwordconfirm_ico_ok").hide();
			$("#passwordconfirm_ico_err").show();
		}
		else if($.trim($("#password").val())==$.trim($("#username").val()) 
				|| $.trim($("#password").val())==($.trim($("#username").val())+$.trim($("#domain").val()))){
			//检查用户名与密码是否相同
			ok=false;
			$("#password").attr("class","inp ipt-error");
			$("#password_ico_ok").hide();
			$("#password_ico_err").show();
			$("#div_password_rule").hide();
			$("#div_password_err").show();
			$("#div_password_err_info").html("输入的密码不能与用户名一样");
		}
	}
	/** 密码保护问题 */
		if($("#secproblem option:selected").val()==0){
			//没有选择问题
			ok=false;
			$("#div_secproblem_err").show();
		}
		else if($("#secproblem option:selected").val()=='cusproblem' ){
			ret=chkCustomProblem();
			if(ret<1){
				ok=false;
				$("#cusproblem").attr("class","inp ipt-error");
				$("#cusproblem_ico_err").show();
				$("#cusproblem_ico_ok").hide();
				$("#div_cusproblem_err").show();
				$("#div_cusproblem_err_info").html("长度太短:6～36个字符,一个汉字占两个字符");
			}
			else {
				$("#secproblem option:selected").attr("value",$.trim($("#cusproblem").val()));
			}
		}
		
		ret=chkSecAnswer();
		if(ret<1){
			ok=false;
			$("#secanswer").addClass("inp ipt-error");
			$("#div_secanswer_rule").hide();
			$("#secanswer_ico_err").show();
			$("#secanswer_ico_ok").hide();
			$("#div_secanswer_err").show();
			$("#div_secanswer_err_info").html("问题答案是:4～30个字符,一个汉字占两个字符");
		}
		
	/** 检查真实姓名*/
		ret=chkrealname();
		if(ret<0){
			ok=false;
			$("#realname").attr("class","inp ipt-error");
			$("#realname_ico_ok").hide();
			$("#realname_ico_err").show();
			$("#div_realname_err").show();
			$("#div_realname_err_info").html("请输入您的真实姓名,长度2-10个中文字符.(如:张三,李四)");
		}
		
		
		
	/** 性别检查 	
		var genders = $("input[name='gender'][checked]");
		if(genders.length==0){
			ok=false;
			$("#div_gender_err").show();
		}*/
		var genders=document.getElementsByName("gender");
		var g=0;
		for(i=0;i<genders.length;i++){
			if(genders[i].checked) g=1;
		}
		if(g==0){
			ok=false;
			$("#div_gender_err").show();
		}
	/** 生日检查 */
		ret=chkYear()*chkMonth()*chkDay();
		var startDate=new Date();
		startDate.setFullYear(1901,0,2);
		var myDate=new Date();
		myDate.setFullYear($.trim($("#year").val()),parseInt($.trim($("#month").val())-1),$.trim($("#day").val()));
		var today=new Date();
		
		if(ret<1 || myDate>today || myDate<startDate){
			ok=false;
			$("#year").attr("class","inp ipt-error");
			$("#month").attr("class","inp ipt-error");
			$("#day").attr("class","inp ipt-error");
			$("#birthday_ico_ok").hide();
			$("#birthday_ico_err").show();
			$("#div_birthday_err").show();
			$("#div_birthday_err").attr("class","info-pop I-error");
			$("#div_birthday_err_info").show();
			$("#div_birthday_err_info").html("请输入有效的出生日期!");
		}else{
			birthday=$.trim($("#year").val())+"-"+$.trim($("#month").val())+"-"+$.trim($("#day").val());
			$("#birthday").attr("value",birthday);
		}
	/** 检查电子邮箱 */
		ret=chkemail();
		if(ret<0){
			ok=false;
			$("#email").attr("class","inp ipt-error");
			$("#email_ico_ok").hide();
			$("#email_ico_err").show();
			$("#div_email_err").show();
			$("#div_email_err_info").html("输入的电子邮箱有错误");
		}
		
	/** 检查验证码 */
		ret=chkAuthcode();
		if(ret<1){
			ok=false;
			$("#authcode").attr("class","inp ipt-error");
			//$("#authcode_ico_ok").hide();
			$("#authcode_ico_err").show();
			$("#div_authcode_err").show();
			$("#div_authcode_err_info").html("验证码不能为空");
		}
		
		//if(ok) doFormRequest('create.jsp','regform');
		if(ok) {
			//$("#reqtime").attr("value",(new Date()).getTime());
			var crypt = hex_md5($("#username").val()+$("#password").val()+$("#birthday").val()).toLowerCase();
			$("#crypt").attr("value",crypt);
			doParameterRequest('create.jsp','authcode','birthday','domain','from','email','password','passwordconfirm','realname','secanswer','secproblem','username','gender','crypt','reqtime');
		}
		else document.body.scrollTop=212;
		//else document.documentElement.scrollTop = 212;
		
		return ok;
}
//获取事件
function fGetEvent (e) {
	var ev = e || window.event;
	
	if (!ev) {
		var aCaller = [];
		var c = fGetEvent.caller;
		while (c) {
			ev = c.arguments[0];
			if (ev && Event == ev.constructor) {
				break;
			}
			
			var b = false;
			for(var i=0;i<aCaller.length;i++){
				if(c == aCaller[i]){
					b = true;
					break;
				}
			}
			if(b){
				break;
			}else{
				aCaller.push(c);
			}
			c = c.caller;
		}
	}

	return ev;
}

function bodyOnLoad(){
	document.getElementById('inp_uname').focus();
	//$(":text").each({"inp_uname"},function(){$(this).attr("value","");});
	//$("#inp_uname").attr("value","");
	$("#authcode").attr("value","");
	$("#cusproblem").attr("value","");
	$("#secanswer").attr("value","");
	$("#username").attr("value","");
	$("#birthday").attr("value","");
	$("#tmp").attr("value","");
	//$(":hidden").each(function(){$(this).attr("value","");});
	//$(":radio:rdAccount").each(function(){$(this).attr("value","");$(this).attr("checked",false);});
	$("input[name='rdAccount']").each(function(){$(this).attr("value","");$(this).attr("checked",false);});
}


function maxDayofDate(myDate){
	 var ary = myDate.toArray();  
	 var date1 = (new Date(ary[0],ary[1]+1,1));  
	 var date2 = date1.dateAdd(1,'m',1);  
	 var result = dateDiff(date1.Format('yyyy-MM-dd'),date2.Format('yyyy-MM-dd'));  
	 return result;  
}
//判断闰年
function isLeapYear(year){
	 return (0==year%4&&((year%100!=0)||(year%400==0)));   
}